package com.lu.dao.impl;

import com.lu.dao.BaseDao;
import com.lu.dao.NewsUsersDao;
import com.lu.entity.NewsUsers;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class NewsUsersDaoImpl extends BaseDao implements NewsUsersDao {
    @Override
    public NewsUsers getOneUser(String uname, String upwd) {
        NewsUsers newsUsers = null;
        Connection con = null;
        PreparedStatement pstmt = null;
        String sql = "select * from NEWS_USERS where uname=? and upwd=?";
        ResultSet rs = null;
        try {
            con = getCon();
            pstmt = con.prepareStatement(sql);
            pstmt.setString(1, uname);
            pstmt.setString(2, upwd);
            rs = pstmt.executeQuery();
            if (rs.next()) {
                int uid = rs.getInt("uid");
                newsUsers = new NewsUsers(uid, uname, upwd);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            closeAll(con, pstmt, rs);
        }
        return newsUsers;
    }
}
